/**
 * 节点类
 */
class Tree {
  constructor (val) {
    this.val = val
    this.left = null
    this.right = null
  }
}
/**
 * 创建二叉树
 * @param {*} list 
 * @returns 
 */
function buildBinaryTree (list) {
  return helper(list, 0)
}
function helper (list, index) {
  if (index >= list.length || list[index] === null || list[index] === undefined) {
    return null
  }
  console.log(index);
  const root = new Tree(list[index])
  root.left = helper(list, 2 * index + 1)
  root.right = helper(list, 2 * index + 2)
  return root
}
const nums = [3, 9, 20, null, null, 15, 7];
const root = buildBinaryTree(nums);
console.log(root);